#!/usr/bin/env python
import sys
import class_set
import helper
from sets import Set

class FeedRecommendationReducer(helper.ReducerHelper):

    def processor(self, key, lst):
        feed = []
        resource = []
        resource_clean = False
        feed_clean = False
        for e in lst:
            recom_tag = class_set.RecomTagFeed('')
            recom_tag.init(e)
            if not recom_tag.getIsResult():
                if recom_tag.getType() == 'resource':
                    resource_clean = True
                else:
                    feed_clean = True
            else:
                if recom_tag.getType() == 'resource':
                    resource.append(recom_tag)
                else:
                    feed.append(recom_tag)

        left, right = self.split(key)
        if not feed_clean:
            for e in feed:
                self.allocator(self.join(left, e.getType()), self.join(right, e))
        if not resource_clean:
            for e in resource:
                self.allocator(self.join(left, e.getType()), self.join(right, e))

def main():
    fr = FeedRecommendationReducer()
    fr.reducer()

if __name__ == '__main__':
    main()









